﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Configuration;
using System.Web;
using System.IO;
using Microsoft.Office.Interop.Word;


namespace Core
{
    public static partial class functional
    {
        public static dynamic word2txt(int eid, Sql.User u, HttpPostedFileBase userfile, string ext,string path)
        {
            Application app = new Application();
            app.Visible = false;
            path = String.Format("{0}\\{1}",path,userfile.FileName);
            object obj = System.Reflection.Missing.Value; 
            Object infile = (object)path;
            try
            {
                Document doc = app.Documents.Open(ref infile, ref obj, ref obj, ref obj, ref obj, ref obj,
                                                    ref obj, ref obj, ref obj, ref obj, ref obj, ref obj,
                                                    ref obj, ref obj, ref obj);
                string content = doc.Content.Text;
                var sql = new Sql.SqlDataContext();
                var sol = sql.DSExperimentSolve.FirstOrDefault(row => row.eid == eid && u.username == row.username);
                sol.reportContent = content;
                return new
                {
                    success = true
                };
            }
            catch (Exception ecp)
            {
                return new
                {
                    success = false,
                    msg = ecp.Message
                };
            }
            
        }
    }
}
